package com.lavender.account.service.controller;

import com.lavender.account.service.entity.Account;
import com.lavender.account.service.service.AccountServiceImpl;
import io.seata.core.context.RootContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author: zhu.chen
 * @date: 2020/11/24
 * @version: v1.0.0
 */
@RestController
public class AccountController {

    @Autowired
    private AccountServiceImpl accountService;

    @GetMapping("debit")
    public Boolean debit(@RequestParam String userId, @RequestParam BigDecimal money) {
        System.out.println("account XID " + RootContext.getXID());
        accountService.debit(userId, money);
        return true;
    }

    // http://localhost:8081/account/insert
    @GetMapping("insert")
    public void insert(){
        Account account = new Account();
        account.setUserId("admin");
        account.setMoney(new BigDecimal(300));
        accountService.insert(account);
    }

}
